package com.ThreadAsist;

import java.util.concurrent.CountDownLatch;
//线程辅助
//线程计数器 - - - - 线程-1记录
public class CountDownLatchs {
    public static void main(String[] args) throws InterruptedException {
        //设置总数
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" GO OUT");
                countDownLatch.countDown();//数量-1
            },String.valueOf(i)).start();
        }
        //等待计数器归0 再向下执行
        //阻塞主线程 等待线程执行完
        countDownLatch.await();
        System.out.println("Close Door");
    }
}
